//
//  MainTabBar.swift
//  DLCjingling
//
//  Created by 顿理超 on 16/4/12.
//  Copyright © 2016年 顿理超. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        //print("\(__FUNCTION__)")
        let btnCount = 5
        let w = self.bounds.size.width / CGFloat(btnCount)
        let h = self.bounds.size.height
        
        let frame = CGRectMake(0, 0, w, h)
        
        var index = 0
        
        for v in subviews as! [UIView]{
        
            if v is UIControl && !(v is UIButton){
            v.frame = CGRectOffset(frame, CGFloat(index) * w, 0)
                
//                index += 1
//                if index == 2 {
//                index += 1
//                }
                index += (index == 1) ? 2 : 1
            }
        }
        
        self.composedButton.frame = frame
        self.composedButton.center = CGPointMake(self.center.x, h * 0.5 )
    }
     lazy var composedButton: UIButton = {
        // btn = UIButton
        let btn = UIButton()
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Selected)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Selected)
        
        self.addSubview(btn)
        
        return btn
    }()
}
